<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动跳转首页</title>

    <style>
        p {
            text-align: center;
        }
        span {
            color: red;
        }
    </style>
</head>
<body>

<p>
    <span id="time">5</span>秒之后，自动跳转到首页...
</p>

<script>

    // 循环定时器，1秒执行一次
    var timeId = setInterval(fun, 1000);

    // 获取倒计时元素
    var time = document.getElementById("time");

    // 显示倒计时效果
    var second = 5;
    function fun() {
        second--;
        if (second <= 0) {
            clearInterval(timeId);
            location.href = "https://www.baidu.com";
            return;
        }
        time.innerHTML = second + "";
    }

</script>

</body>
</html>